package com.cxhc.app.api.hcdoc;


import com.cxhc.app.api.hcdoc.vo.HdUserInfoVo;
import com.cxhc.app.api.mapper.SysUserMapStructMapper;
import com.cxhc.app.api.mapper.hcdoc.HcDocUserMapStructMapper;
import com.cxhc.app.api.vo.AppUserVo;
import com.cxhc.app.api.vo.SysUserVo;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.core.domain.entity.SysUser;
import com.cxhc.common.core.page.TableDataInfo;
import com.cxhc.common.utils.StringUtils;
import com.cxhc.system.domain.hcdoc.HdUserInfo;
import com.cxhc.system.service.hcdoc.HcDocUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户信息Controller
 *
 * @author Dhq
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/api/hcDoc/user")
public class HcDocUserApi extends BaseController {

    @Autowired
    private HcDocUserService hcDocUserService;

    /**
     * 获取用户信息详细信息
     */
    @RequestMapping(value = "/getInfoByAccount")
    public AjaxResult getInfoByAccount(String accountNo) {
        if (StringUtils.isEmpty(accountNo)){
            return error("账号不可为空!!!");
        }
        return success(hcDocUserService.selectUserByAccountNoForHCDoc(accountNo));
    }

    /**
     * 新增用户信息
     */
    @RequestMapping("/insert")
    public AjaxResult insert(@RequestBody HdUserInfoVo hdUserInfoVo) {
        HdUserInfo hdUserInfo = HcDocUserMapStructMapper.INSTANCE.HdUserInfoVoToHdUserInfo(hdUserInfoVo);
        return toAjax(hcDocUserService.insertHcUser(hdUserInfo));
    }

    /**
     * 查询用户信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HdUserInfoVo hdUserInfoVo) {
        HdUserInfo hdUserInfo = HcDocUserMapStructMapper.INSTANCE.HdUserInfoVoToHdUserInfo(hdUserInfoVo);
        startPage();
        return getDataTable(hcDocUserService.selectList(hdUserInfo));
    }

    /**
     * 查询用户信息列表
     */
    @GetMapping("/update")
    public AjaxResult update(HdUserInfoVo hdUserInfoVo) {
        HdUserInfo hdUserInfo = HcDocUserMapStructMapper.INSTANCE.HdUserInfoVoToHdUserInfo(hdUserInfoVo);
        if (StringUtils.isEmpty(hdUserInfo.getAccountNo())){
            return error("账号不可为空!!!");
        }
        return toAjax(hcDocUserService.update(hdUserInfo));
    }

    /**
     * 新增用户信息
     */
    @RequestMapping("/delete")
    public AjaxResult delete(String accountNo) {
        if (StringUtils.isEmpty(accountNo)){
            return error("账号不可为空!!!");
        }
        return success(hcDocUserService.delete(accountNo));
    }
}
